public function view()
 {
     if (!($email_template_id = $this->_context[0])) {
         redirect(extension_members::baseURL());
     }
     if (!($existing = EmailTemplate::loadFromID($email_template_id))) {
         throw new SymphonyErrorPage(__('The email template you requested to edit does not exist.'), __('Email Template not found'), 'error');
     }
     if (isset($this->_context[1])) {
         switch ($this->_context[1]) {
             case 'saved':
                 $this->pageAlert(__('Email Template updated at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Email Template</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'email_templates_new/', extension_members::baseURL() . 'email_templates/')), Alert::SUCCESS);
                 break;
             case 'created':
                 $this->pageAlert(__('Email Template created at %1$s. <a href="%2$s">Create another?</a> <a href="%3$s">View all Email Template</a>', array(DateTimeObj::getTimeAgo(__SYM_TIME_FORMAT__), extension_members::baseURL() . 'email_templates_new/', extension_members::baseURL() . 'email_templates/')), Alert::SUCCESS);
                 break;
         }
     }
     Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/styles.css', 'screen', 9125341);
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert(__('An error occurred while processing this form. <a href="#error">See below for details.</a>'), AdministrationPage::PAGE_ALERT_ERROR);
     }
     $this->setPageType('form');
     $this->setTitle('Symphony &ndash; Member Roles &ndash; ' . $existing->subject);
     $this->appendSubheading($existing->subject);
     $fields = array();
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
     } else {
         $fields['subject'] = $existing->subject;
         $fields['body'] = $existing->body;
         $fields['type'] = $existing->type;
         $fields['roles'] = NULL;
         foreach ($existing->roles() as $role_id => $r) {
             $fields['roles'] .= $r->name() . ", ";
         }
         $fields['roles'] = trim($fields['roles'], ', ');
     }
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'primary');
     $label = Widget::Label('Subject');
     $label->appendChild(Widget::Input('fields[subject]', General::sanitize($fields['subject'])));
     if (isset($this->_errors['subject'])) {
         $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['subject']));
     } else {
         $fieldset->appendChild($label);
     }
     $label = Widget::Label('Body');
     $label->appendChild(Widget::Textarea('fields[body]', 15, 75, General::sanitize($fields['body'])));
     if (isset($this->_errors['body'])) {
         $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['body']));
     } else {
         $fieldset->appendChild($label);
     }
     $fieldset->appendChild(new XMLElement('p', 'Dynamic fields and parameters can be included in the subject or body of the email using the <code>{$param}</code> syntax. Please see the <a href="http://github.com/symphony/members/blob/master/README.markdown">readme</a> for a complete list of available parameters.', array('class' => 'help')));
     $this->Form->appendChild($fieldset);
     $sidebar = new XMLElement('fieldset');
     $sidebar->setAttribute('class', 'secondary');
     $label = Widget::Label('Type');
     $options = array(array(NULL, false, NULL), array('reset-password', $fields['type'] == 'reset-password', 'Reset Password'), array('new-password', $fields['type'] == 'new-password', 'New Password'), array('activate-account', $fields['type'] == 'activate-account', 'Activate Account'), array('welcome', $fields['type'] == 'welcome', 'Welcome Email'));
     $label->appendChild(Widget::Select('fields[type]', $options));
     if (isset($this->_errors['type'])) {
         $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['type']));
     } else {
         $sidebar->appendChild($label);
     }
     $label = Widget::Label('Roles');
     $label->appendChild(Widget::Input('fields[roles]', $fields['roles']));
     if (isset($this->_errors['roles'])) {
         $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['roles']));
     } else {
         $sidebar->appendChild($label);
     }
     $roles = DatabaseUtilities::resultColumn(ASDCLoader::instance()->query("SELECT `name` FROM `tbl_members_roles` ORDER BY `name` ASC"), 'name');
     if (is_array($roles) && !empty($roles)) {
         $taglist = new XMLElement('ul');
         $taglist->setAttribute('class', 'tags');
         foreach ($roles as $tag) {
             $taglist->appendChild(new XMLElement('li', $tag));
         }
         $sidebar->appendChild($taglist);
     }
     $this->Form->appendChild($sidebar);
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', 'Save Changes', 'submit', array('accesskey' => 's')));
     $button = new XMLElement('button', __('Delete'));
     $button->setAttributeArray(array('name' => 'action[delete]', 'class' => 'confirm delete', 'title' => __('Delete this email template')));
     $div->appendChild($button);
     $this->Form->appendChild($div);
 }
 public function view()
 {
     Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/members/assets/styles.css', 'screen', 9125341);
     $formHasErrors = is_array($this->_errors) && !empty($this->_errors);
     if ($formHasErrors) {
         $this->pageAlert('An error occurred while processing this form. <a href="#error">See below for details.</a>', AdministrationPage::PAGE_ALERT_ERROR);
     }
     $this->setPageType('form');
     $this->appendSubheading('Untitled');
     $fields = array();
     if (isset($_POST['fields'])) {
         $fields = $_POST['fields'];
     }
     $fieldset = new XMLElement('fieldset');
     $fieldset->setAttribute('class', 'primary');
     $label = Widget::Label('Subject');
     $label->appendChild(Widget::Input('fields[subject]', General::sanitize($fields['subject'])));
     if (isset($this->_errors['subject'])) {
         $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['subject']));
     } else {
         $fieldset->appendChild($label);
     }
     $label = Widget::Label('Body');
     $label->appendChild(Widget::Textarea('fields[body]', 15, 75, General::sanitize($fields['body'])));
     if (isset($this->_errors['body'])) {
         $fieldset->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['body']));
     } else {
         $fieldset->appendChild($label);
     }
     $fieldset->appendChild(new XMLElement('p', 'Dynamic fields and parameters can be included in the subject or body of the email using the <code>{$param}</code> syntax. Please see the <a href="http://github.com/symphony/members/blob/master/README.markdown">readme</a> for a complete list of available parameters.', array('class' => 'help')));
     $this->Form->appendChild($fieldset);
     $sidebar = new XMLElement('fieldset');
     $sidebar->setAttribute('class', 'secondary');
     $label = Widget::Label('Type');
     $options = array(array(NULL, false, NULL), array('reset-password', $fields['type'] == 'reset-password', 'Reset Password'), array('new-password', $fields['type'] == 'new-password', 'New Password'), array('activate-account', $fields['type'] == 'activate-account', 'Activate Account'), array('welcome', $fields['type'] == 'welcome', 'Welcome Email'));
     $label->appendChild(Widget::Select('fields[type]', $options));
     if (isset($this->_errors['type'])) {
         $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['type']));
     } else {
         $sidebar->appendChild($label);
     }
     $label = Widget::Label('Roles');
     $label->appendChild(Widget::Input('fields[roles]', $fields['roles']));
     if (isset($this->_errors['roles'])) {
         $sidebar->appendChild(Widget::wrapFormElementWithError($label, $this->_errors['roles']));
     } else {
         $sidebar->appendChild($label);
     }
     $roles = DatabaseUtilities::resultColumn(ASDCLoader::instance()->query("SELECT `name` FROM `tbl_members_roles` ORDER BY `name` ASC"), 'name');
     if (is_array($roles) && !empty($roles)) {
         $taglist = new XMLElement('ul');
         $taglist->setAttribute('class', 'tags');
         foreach ($roles as $tag) {
             $taglist->appendChild(new XMLElement('li', $tag));
         }
         $sidebar->appendChild($taglist);
     }
     $this->Form->appendChild($sidebar);
     $div = new XMLElement('div');
     $div->setAttribute('class', 'actions');
     $div->appendChild(Widget::Input('action[save]', 'Create', 'submit', array('accesskey' => 's')));
     $this->Form->appendChild($div);
 }
    public function grab(&$param_pool)
    {
        $Members = Frontend::instance()->ExtensionManager->create('members');
        $Members->initialiseCookie();
        if ($Members->isLoggedIn() !== true) {
            // Oi! you can't be here
            redirect(URL . '/forbidden/');
            exit;
        }
        $result = new XMLElement($this->dsParamROOTELEMENT);
        self::__init();
        $db = ASDCLoader::instance();
        $sql = 'SELECT SQL_CALC_FOUND_ROWS 
						pinned.entry_id AS `id`, 
						pinned.value AS `pinned`, 
						closed.value AS `closed`, 
						creation_date.local AS `creation-date`,
						last_active.local AS `last-active`,							
						created_by.member_id AS `created-by-member-id`,
						created_by.username AS `created-by-username`,
						last_post.member_id AS `last-post-member-id`,
						last_post.username AS `last-post-username`,							
						topic.value AS `topic`
					
					FROM `tbl_entries_data_%d` AS `pinned`
					LEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id
					LEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id	
					LEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id					
					LEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id	
					LEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id	
					LEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id
					LEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id
					LEFT JOIN `tbl_entries_data_%d` AS `discussion_comments_member` ON comments.entry_id = discussion_comments_member.entry_id	
					WHERE 1 %s
					AND (created_by.member_id = %11$d || discussion_comments_member.member_id = %11$d)
					GROUP BY pinned.entry_id
					ORDER BY pinned.value ASC, last_active.local DESC
					LIMIT %12$d, %13$d';
        try {
            $rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), self::findFieldID('created-by', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id  = " . (int) $this->dsParamFILTERS['id'] : NULL, (int) $Members->Member->get('id'), max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT));
        } catch (Exception $e) {
            $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
            return $result;
        }
        if ($rows->length() == 0) {
            return $this->emptyXMLSet();
        }
        $total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
        $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE));
        /*
        	stdClass Object
        	(
        	    [id] => 666
        	    [pinned] => yes
        	    [closed] => no
        	    [creation-date] => 1233599808
        	    [last-active] => 1237161637
        	    [created-by-member-id] => 2126
        	    [created-by-username] => Lewis
        	    [last-post-member-id] => 2126
        	    [last-post-username] => Lewis
        	    [topic] => Symphony 2 Documentation
        	    [comments] => 18
        	)
        
           <entry id="595" comments="7">
        		            <created-by id="2150">newnomad</created-by>
        		            <closed>No</closed>
        		            <last-active time="18:30" weekday="1">2009-02-09</last-active>
        		            <last-post id="2150">newnomad</last-post>
        		            <pinned>No</pinned>
        		            <topic handle="viewing-feeds">viewing feeds</topic>
        		            <creation-date time="19:31" weekday="3">2009-01-07</creation-date>
            </entry>
        */
        $param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id');
        foreach ($rows as $r) {
            // Need to do a seperate query to find the comment counts.
            try {
                $comments = $db->query(sprintf("SELECT COUNT(*) AS `count` FROM `tbl_entries_data_%d` WHERE `relation_id` = %d ", self::findFieldID('parent-id', 'comments'), $r->id))->current()->count;
            } catch (Exception $e) {
                $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
                return $result;
            }
            $entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $comments));
            $entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'})));
            $entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'})));
            $entry->appendChild(new XMLElement('closed', ucfirst($r->closed)));
            $entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned)));
            $entry->appendChild(new XMLElement('topic', General::sanitize($r->topic)));
            $entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date'));
            $entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active'));
            $result->appendChild($entry);
        }
        return $result;
    }
Пример #4
0
 public function grab(&$param_pool)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     self::__init();
     $db = ASDCLoader::instance();
     $sql = "SELECT SQL_CALC_FOUND_ROWS \n\t\t\t\t\t\tpinned.entry_id AS `id`, \n\t\t\t\t\t\tpinned.value AS `pinned`, \n\t\t\t\t\t\tclosed.value AS `closed`, \n\t\t\t\t\t\tcreation_date.local AS `creation-date`,\n\t\t\t\t\t\tlast_active.local AS `last-active`,\t\t\t\t\t\t\t\n\t\t\t\t\t\tcreated_by.member_id AS `created-by-member-id`,\n\t\t\t\t\t\tcreated_by.username AS `created-by-username`,\n\t\t\t\t\t\tlast_post.member_id AS `last-post-member-id`,\n\t\t\t\t\t\tlast_post.username AS `last-post-username`,\t\t\t\t\t\t\t\n\t\t\t\t\t\ttopic.value AS `topic`,\n\t\t\t\t\t\tCOUNT(comments.relation_id) AS `comments`\n\t\t\t\t\t\n\t\t\t\t\tFROM `tbl_entries_data_%d` AS `pinned`\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id\t\t\t\t\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id\n\t\t\t\t\tWHERE 1 %s\n\t\t\t\t\tGROUP BY pinned.entry_id\n\t\t\t\t\tORDER BY pinned.value ASC, last_active.local DESC\n\t\t\t\t\tLIMIT %d, %d";
     try {
         $rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id  = " . (int) $this->dsParamFILTERS['id'] : NULL, max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT));
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError()))));
         return $result;
     }
     if ($rows->length() == 0 && strlen(trim($dsParamFILTERS['id'])) > 0) {
         $this->__redirectToErrorPage();
     } elseif ($rows->length() == 0) {
         return $this->emptyXMLSet();
     }
     $total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total;
     $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE));
     /*
     	stdClass Object
     	(
     	    [id] => 666
     	    [pinned] => yes
     	    [closed] => no
     	    [creation-date] => 1233599808
     	    [last-active] => 1237161637
     	    [created-by-member-id] => 2126
     	    [created-by-username] => Lewis
     	    [last-post-member-id] => 2126
     	    [last-post-username] => Lewis
     	    [topic] => Symphony 2 Documentation
     	    [comments] => 18
     	)
     
        <entry id="595" comments="7">
     		            <created-by id="2150">newnomad</created-by>
     		            <closed>No</closed>
     		            <last-active time="18:30" weekday="1">2009-02-09</last-active>
     		            <last-post id="2150">newnomad</last-post>
     		            <pinned>No</pinned>
     		            <topic handle="viewing-feeds">viewing feeds</topic>
     		            <creation-date time="19:31" weekday="3">2009-01-07</creation-date>
         </entry>
     */
     $param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id');
     foreach ($rows as $r) {
         $entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $r->comments));
         $entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'})));
         $entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'})));
         $entry->appendChild(new XMLElement('closed', ucfirst($r->closed)));
         $entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned)));
         $entry->appendChild(new XMLElement('topic', General::sanitize($r->topic)));
         $entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date'));
         $entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active'));
         $result->appendChild($entry);
     }
     return $result;
 }